package com.hqm.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.hqm.meta.Transaction;

@Repository
public interface TransactionDao {
	@Insert("INSERT trx(contentId, userId, price, time) "
			+ "VALUES(#{contentid}, #{userid}, #{price}, #{time})")
	Integer addTrxRecord(Transaction transaction);
	
	@Select("SELECT count(*) FROM trx WHERE contentId=#{contentId}")
	Integer getProSoldCnts(@Param("contentId") Integer contentId);
	
	@Select("SELECT count(*) FROM trx WHERE contentId=#{contentId} and userId=#{userId}")
	Integer getProBuyedCnts(@Param("contentId") Integer contentId, 
			@Param("userId") Integer userId);
	
	@Select("SELECT * FROM trx WHERE userId=#{userId} and contentId=#{contentId}")
	List<Transaction> getTransaction(@Param("contentId") Integer contentId,
			@Param("userId") Integer userId);
	
	@Select("SELECT * FROM trx WHERE userId=#{userId}")
	List<Transaction> getTransactionForBuyer(@Param("userId") Integer userId);
}
